home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Easy Applet Builder v1.7 / _SETUP.1 / Link.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  4.6 KB  |  200 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Cursor;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Label;
  7. import java.awt.event.MouseEvent;
  8. import java.awt.event.MouseListener;
  9. import java.awt.event.MouseMotionListener;
  10. import java.net.URL;
  11.  
  12. class Link extends Label implements MouseListener, MouseMotionListener, Runnable {
  13.    ScrollBoxLink sbl;
  14.    Font normalFont;
  15.    Font enterFont;
  16.    String link;
  17.    String statusText;
  18.    Thread thread;
  19.    boolean move;
  20.  
  21.    public Link() {
  22.    }
  23.  
  24.    public Link(String label, ScrollBoxLink sbl, String link, String status) {
  25.       super(label);
  26.       this.sbl = sbl;
  27.       this.link = link;
  28.       this.statusText = status;
  29.       Font f = ((Component)this).getFont();
  30.       String fontName = ((Applet)sbl).getParameter("text_font_name");
  31.       if (fontName == null) {
  32.          fontName = f.getName();
  33.       }
  34.  
  35.       String s = ((Applet)sbl).getParameter("text_font_height");
  36.       int textHeight;
  37.       if (s != null) {
  38.          textHeight = Integer.parseInt(s);
  39.       } else {
  40.          textHeight = 12;
  41.       }
  42.  
  43.       s = ((Applet)sbl).getParameter("text_enter_font_height");
  44.       int enterTextHeight;
  45.       if (s != null) {
  46.          enterTextHeight = Integer.parseInt(s);
  47.       } else {
  48.          enterTextHeight = textHeight;
  49.       }
  50.  
  51.       int style = 0;
  52.       s = ((Applet)sbl).getParameter("text_font_style");
  53.       if (s != null) {
  54.          if (s.equals("bold")) {
  55.             style = 1;
  56.          } else if (s.equals("italic")) {
  57.             style = 2;
  58.          } else if (s.equals("bold_italic")) {
  59.             style = 3;
  60.          } else {
  61.             style = 0;
  62.          }
  63.       }
  64.  
  65.       int enterStyle = style;
  66.       s = ((Applet)sbl).getParameter("text_enter_font_style");
  67.       if (s != null) {
  68.          if (s.equals("bold")) {
  69.             enterStyle = 1;
  70.          } else if (s.equals("italic")) {
  71.             enterStyle = 2;
  72.          } else if (s.equals("bold_italic")) {
  73.             enterStyle = 3;
  74.          }
  75.       }
  76.  
  77.       try {
  78.          this.normalFont = new Font(fontName, style, textHeight);
  79.          this.enterFont = new Font(fontName, enterStyle, enterTextHeight);
  80.          ((Component)this).setFont(this.normalFont);
  81.       } catch (Exception var12) {
  82.          this.normalFont = new Font(f.getName(), style, textHeight);
  83.          this.enterFont = new Font(f.getName(), enterStyle, enterTextHeight);
  84.          ((Component)this).setFont(this.normalFont);
  85.       }
  86.  
  87.       if (sbl.justify == 1) {
  88.          ((Label)this).setAlignment(1);
  89.       }
  90.  
  91.       ((Component)this).addMouseListener(this);
  92.       ((Component)this).addMouseMotionListener(this);
  93.       ((Component)this).setForeground(sbl.normalColor);
  94.    }
  95.  
  96.    public void start() {
  97.       if (this.thread == null) {
  98.          this.move = true;
  99.          this.thread = new Thread(this);
  100.          this.thread.start();
  101.       }
  102.  
  103.    }
  104.  
  105.    public void stop() {
  106.       if (this.thread != null) {
  107.          this.move = false;
  108.          this.thread = null;
  109.       }
  110.  
  111.    }
  112.  
  113.    public void run() {
  114.       this.move = true;
  115.       int c = 1;
  116.  
  117.       while(this.move) {
  118.          if (c == 0) {
  119.             ((Component)this).setForeground(this.sbl.normalColor);
  120.          } else {
  121.             ((Component)this).setForeground(this.sbl.enterColor);
  122.          }
  123.  
  124.          ((Component)this).repaint();
  125.          c = 1 - c;
  126.  
  127.          try {
  128.             Thread.sleep((long)this.sbl.pause);
  129.          } catch (InterruptedException var2) {
  130.             this.stop();
  131.          }
  132.       }
  133.  
  134.       this.stop();
  135.    }
  136.  
  137.    public void update(Graphics g) {
  138.       ((Component)this).paint(g);
  139.    }
  140.  
  141.    public void mouseClicked(MouseEvent e) {
  142.    }
  143.  
  144.    public void mouseEntered(MouseEvent e) {
  145.       ((Component)this).setForeground(this.sbl.enterColor);
  146.       ((Component)this).setFont(this.enterFont);
  147.       if (this.statusText != null) {
  148.          this.sbl.showStatus(this.statusText);
  149.       }
  150.  
  151.       if (this.sbl.hand) {
  152.          this.sbl.setCursor(new Cursor(12));
  153.       }
  154.  
  155.       if (this.sbl.animated) {
  156.          this.thread = new Thread(this);
  157.          this.thread.start();
  158.       }
  159.  
  160.       ((Component)this).repaint();
  161.    }
  162.  
  163.    public void mouseExited(MouseEvent e) {
  164.       if (this.sbl.animated) {
  165.          this.move = false;
  166.       }
  167.  
  168.       ((Component)this).setForeground(this.sbl.normalColor);
  169.       ((Component)this).setFont(this.normalFont);
  170.       if (this.sbl.hand) {
  171.          this.sbl.setCursor(new Cursor(0));
  172.       }
  173.  
  174.       ((Component)this).repaint();
  175.    }
  176.  
  177.    public void mousePressed(MouseEvent e) {
  178.       if (this.sbl.clicSound != null) {
  179.          this.sbl.clicSound.play();
  180.       }
  181.  
  182.       URL u = this.sbl.giveURL(this.link);
  183.       String target = this.sbl.getParameter("target");
  184.       if (target == null) {
  185.          target = "_blank";
  186.       }
  187.  
  188.       this.sbl.getAppletContext().showDocument(u, target);
  189.    }
  190.  
  191.    public void mouseReleased(MouseEvent e) {
  192.    }
  193.  
  194.    public void mouseDragged(MouseEvent e) {
  195.    }
  196.  
  197.    public void mouseMoved(MouseEvent e) {
  198.    }
  199. }
  200.